import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:smart_shop/pages/home/home_search_bar.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // 1. 定义字典存储接口数据
  Map resData = {};

  @override
  void initState() {
    getResData();
    super.initState();
  }

  // 2. 获取接口数据
  void getResData() async {
    Dio dio = Dio();
    Response res = await dio
        .get('http://smart-shop.itheima.net/index.php?s=/api/page/detail');
    print(res.data);
    setState(() {
      resData = res.data['data']['pageData'];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          '首页',
          style: TextStyle(color: Colors.white),
        ),
        backgroundColor: Colors.red,
        centerTitle: true,
      ),
      body: ListView(
        children: const [HomeSearchBar()],
      ),
    );
  }
}
